package no.uio.ifi.cop.prover.cmp;

import java.util.Comparator;

import no.uio.ifi.cop.prover.RuleMatcher;
import no.uio.ifi.cop.cl.Axiom;


/**
 * Natural ordering, with minor twist.
 *
 * Basically what we do is this:
 * Natural priority is used, but if two rules have the same
 * priority, we prefer rules read in last, as to those read
 * in first, yes this is a minor change to a somewhat dubious
 * preference.
 *
 * @version 1.0
 * @author bjarneh@ifi.uio.no
 */

public class ReverseOrder implements Comparator<RuleMatcher>{

    public int compare(RuleMatcher first, RuleMatcher second){

        int firstType, secondType, firstId, secondId;

        if( first == second ){ return 0; }

        firstType   = first.getAxiom().getType();
        secondType  = second.getAxiom().getType();
        firstId     = first.getId();
        secondId    = second.getId();

        if( firstType < secondType ){
            return -1;
        }else if( firstType > secondType ){
            return 1;
        }else{
            if( firstId > secondId ){
                return -1;
            }else if( firstId < secondId ){
                return 1;
            }
        }

        return 0;

    }
}
